package ict.kth.se.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;

/**
 * This class extends User from springframework to enable authentication
 * @author stefan
 *
 */
public class Person extends org.springframework.security.core.userdetails.User{

	private static final long serialVersionUID = 176125367L;
	
	private static final String TEMPORARY_USERNAME_AND_PASSWORD = "temp";
	public static final String PASSWORD_ENCRYPT_SALT = "MySalt";
	
	private Long id;
	private String firstName;
	private String lastName;
	private String ssn;
	private String email;
	private Role role;
	private List<Availability> availabilities;
	private List<CompetenceProfile> competenceProfiles;
	
	
	/**
	 * Constructor to set required variables for super class
	 * @param id person id
	 * @param firstName person name
	 * @param lastName person lastname
	 * @param ssn social security number
	 * @param email persons email
	 * @param username persons username
	 * @param password persons password
	 * @param userEnabled boolean userenabled
	 * @param authorities collection of authorities
	 */
	public Person(Long id, String firstName, String lastName, String ssn, String email, 
			String username, String password, boolean userEnabled,
			Collection<? extends GrantedAuthority> authorities) {
		
		//Constructor for super class
		super(username, password, userEnabled, true, true, true, authorities);
		this.id = id;
		this.firstName = firstName;
		this.lastName = lastName;
		this.ssn = ssn;
		this.email = email;
	}
	
	
	/**
	 * Constructor to set required variables for super class without Id - For insertion
	 * @param firstName persons firstname
	 * @param lastName persons lastname
	 * @param ssn social security number
	 * @param email person email
	 * @param username person username
	 * @param password person password
	 * @param userEnabled boolean userenabled
	 * @param authorities collection of authorities
	 */
	public Person(String firstName, String lastName, String ssn, String email, 
			String username, String password, boolean userEnabled,
			Collection<? extends GrantedAuthority> authorities) {
		
		//Constructor for super class
		super(username, password, userEnabled, true, true, true, authorities);
		this.firstName = firstName;
		this.lastName = lastName;
		this.ssn = ssn;
		this.email = email;
	}
	
	/**
	 * Empty constructor
	 * @param firstName user firstname
	 * @param lastName user lastname
	 * @param email user email
	 */
	public Person(String firstName, String lastName, String email){
		super(TEMPORARY_USERNAME_AND_PASSWORD, TEMPORARY_USERNAME_AND_PASSWORD, false, true, true, true, new ArrayList<GrantedAuthority>());
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<CompetenceProfile> getCompetenceProfiles() {
		return competenceProfiles;
	}
	public void setCompetenceProfiles(List<CompetenceProfile> competenceProfiles) {
		this.competenceProfiles = competenceProfiles;
	}
	public List<Availability> getAvailabilities() {
		return availabilities;
	}
	public void setAvailabilities(List<Availability> availabilities) {
		this.availabilities = availabilities;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getSsn() {
		return ssn;
	}
	public void setSsn(String ssn) {
		this.ssn = ssn;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	
	
	
}
